home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Harvest C 1.3 / Application / Examples / Harvest Bullseye / bullseye.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-20  |  2.7 KB  |  168 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * bullseye.c
  3.  *
  4.  *    A simple demonstration program to play with the debugger
  5.  *
  6.  *
  7.  *****/
  8.  
  9. #include <Windows.h>
  10. #include <Menus.h>
  11. #include <Fonts.h>
  12. #include <Dialogs.h>
  13. #include <Memory.h>
  14. #include <Events.h>
  15. #include <OSEvents.h>
  16. #include <Desk.h>
  17.  
  18. #include "bullMenus.h"
  19. #include "bullWindow.h"
  20.  
  21. extern    WindowPtr    bullseyeWindow;
  22. extern    Rect        dragRect;
  23.  
  24. void InitMacintosh(void);
  25. void HandleMouseDown (EventRecord    *theEvent);
  26. void HandleEvent(void);
  27.  
  28. /****
  29.  * InitMacintosh()
  30.  *
  31.  * Initialize all the managers & memory
  32.  *
  33.  ****/
  34.  
  35. void InitMacintosh(void)
  36.  
  37. {
  38.     MaxApplZone();
  39.     
  40.     InitGraf(&(qd.thePort));
  41.     InitFonts();
  42.     FlushEvents(everyEvent, 0);
  43.     InitWindows();
  44.     InitMenus();
  45.     TEInit();
  46.     InitDialogs(0L);
  47.     InitCursor();
  48.  
  49. }
  50. /* end InitMacintosh */
  51.  
  52.  
  53. /****
  54.  * HandleMouseDown (theEvent)
  55.  *
  56.  *    Take care of mouseDown events.
  57.  *
  58.  ****/
  59.  
  60. void HandleMouseDown (EventRecord    *theEvent)
  61.  
  62. {
  63.     WindowPtr    theWindow;
  64.     int            windowCode = FindWindow (theEvent->where, &theWindow);
  65.     
  66.     switch (windowCode)
  67.       {
  68.       case inSysWindow: 
  69.         SystemClick (theEvent, theWindow);
  70.         break;
  71.         
  72.       case inMenuBar:
  73.           AdjustMenus();
  74.         HandleMenu(MenuSelect(theEvent->where));
  75.         break;
  76.         
  77.       case inDrag:
  78.           if (theWindow == bullseyeWindow)
  79.             DragWindow(bullseyeWindow, theEvent->where, &dragRect);
  80.             break;
  81.             
  82.       case inContent:
  83.           if (theWindow == bullseyeWindow)
  84.             {
  85.             if (theWindow != FrontWindow())
  86.               SelectWindow(bullseyeWindow);
  87.             else
  88.               InvalRect(&bullseyeWindow->portRect);
  89.             }
  90.           break;
  91.           
  92.       case inGoAway:
  93.           if (theWindow == bullseyeWindow && 
  94.               TrackGoAway(bullseyeWindow, theEvent->where))
  95.           HideWindow(bullseyeWindow);
  96.             break;
  97.       }
  98. }
  99. /* end HandleMouseDown */
  100.  
  101.  
  102. /****
  103.  * HandleEvent()
  104.  *
  105.  *        The main event dispatcher. This routine should be called
  106.  *        repeatedly (it  handles only one event).
  107.  *
  108.  *****/
  109.  
  110. void HandleEvent(void)
  111.  
  112. {
  113.     int            ok;
  114.     EventRecord    theEvent;
  115.  
  116.     HiliteMenu(0);
  117.     SystemTask ();        /* Handle desk accessories */
  118.     
  119.     ok = GetNextEvent (everyEvent, &theEvent);
  120.     if (ok)
  121.       switch (theEvent.what)
  122.         {
  123.         case mouseDown:
  124.             HandleMouseDown(&theEvent);
  125.             break;
  126.             
  127.         case keyDown: 
  128.         case autoKey:
  129.             if ((theEvent.modifiers & cmdKey) != 0)
  130.               {
  131.               AdjustMenus();
  132.               HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
  133.               }
  134.             break;
  135.             
  136.         case updateEvt:
  137.             BeginUpdate(bullseyeWindow);
  138.             DrawBullseye(((WindowPeek) bullseyeWindow)->hilited);
  139.             EndUpdate(bullseyeWindow);
  140.             break;
  141.             
  142.         case activateEvt:
  143.             InvalRect(&bullseyeWindow->portRect);
  144.             break;
  145.         }
  146. }
  147. /* end HandleEvent */
  148.  
  149.  
  150. /*****
  151.  * main()
  152.  *
  153.  *    This is where everything happens
  154.  *
  155.  *****/
  156.  
  157.  
  158. main()
  159.  
  160. {
  161.     InitMacintosh();
  162.     SetUpMenus();
  163.     SetUpWindow();
  164.     
  165.     for (;;)
  166.         HandleEvent();
  167. }
  168. /* end main */